package com.itheima;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class Demo01 {
    public static void main(String[] args) throws Exception{
        //1 读取核心配置文件
        InputStream is = Resources.getResourceAsStream("sql.xml");
        //2 构建SqlSessionFactory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //3 获取SQL Session对象
        SqlSession session = factory.openSession();
        //4 调用statement对象
        //写法: namespace + "." + statement对象的id
        int i = session.selectOne("one.count");
        System.out.println(i);
        //5 事务提交
        session.commit();
        //6 释放资源
        is.close();
        session.close();
    }
}
